
<!DOCTYPE HTML>
<html lang="en" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Thread知多少 · smartboot 中文指南</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters-interactive/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../../donation.html" />
    
    
    <link rel="prev" href="../firstfit/readme.html" />
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"buttons":[{"user":"smartboot","repo":"smart-socket","type":"star","size":"small","count":true}]};
    </script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    关于smartboot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    smart-socket 使用手册
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../../smart-socket/">
            
                <a href="../../smart-socket/">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" >
            
                <span>
            
                    
                    第一章 smart-socket开发指南
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.2.1" data-path="../../smart-socket/chapter-1/2.1-基础应用/">
            
                <a href="../../smart-socket/chapter-1/2.1-基础应用/">
            
                    
                    1.1 快速上手
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.2" data-path="../../smart-socket/chapter-1/2.2-Spring集成/">
            
                <a href="../../smart-socket/chapter-1/2.2-Spring集成/">
            
                    
                    1.2 Spring集成smart-socket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.3" data-path="../../smart-socket/chapter-1/SUMMARY.html">
            
                <a href="../../smart-socket/chapter-1/SUMMARY.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../../smart-socket/chapter-2/">
            
                <a href="../../smart-socket/chapter-2/">
            
                    
                    第二章 源码解析
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.3.1" data-path="../../smart-socket/chapter-2/核心接口/">
            
                <a href="../../smart-socket/chapter-2/核心接口/">
            
                    
                    2.1 核心接口与状态机
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.2" data-path="../../smart-socket/chapter-2/服务端/">
            
                <a href="../../smart-socket/chapter-2/服务端/">
            
                    
                    2.2 服务端
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.3" data-path="../../smart-socket/chapter-2/客户端/">
            
                <a href="../../smart-socket/chapter-2/客户端/">
            
                    
                    2.3 客户端
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.4" data-path="../../smart-socket/chapter-2/AioSession/">
            
                <a href="../../smart-socket/chapter-2/AioSession/">
            
                    
                    2.4 会话AioSession
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.5" data-path="../../smart-socket/chapter-2/SUMMARY.html">
            
                <a href="../../smart-socket/chapter-2/SUMMARY.html">
            
                    
                    2.5 小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../../smart-socket/chapter-3/">
            
                <a href="../../smart-socket/chapter-3/">
            
                    
                    第三章 通信协议
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.4.1" data-path="../../smart-socket/chapter-3/1-消息归类/">
            
                <a href="../../smart-socket/chapter-3/1-消息归类/">
            
                    
                    3.1 消息归类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.2" data-path="../../smart-socket/BLANK.html">
            
                <a href="../../smart-socket/BLANK.html">
            
                    
                    3.2 半包/粘包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.3" data-path="../../smart-socket/BLANK.html">
            
                <a href="../../smart-socket/BLANK.html">
            
                    
                    3.3 Http消息解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.4" data-path="../../smart-socket/BLANK.html">
            
                <a href="../../smart-socket/BLANK.html">
            
                    
                    3.4 RPC消息解析
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../../smart-socket/chapter-5/">
            
                <a href="../../smart-socket/chapter-5/">
            
                    
                    第四章 内存池
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../../smart-socket/chapter-6/">
            
                <a href="../../smart-socket/chapter-6/">
            
                    
                    第五章 未来规划
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../../smart-socket/end/">
            
                <a href="../../smart-socket/end/">
            
                    
                    附录
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    smart-http 实战手册
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../../smart-http/">
            
                <a href="../../smart-http/">
            
                    
                    关于smart-http
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" >
            
                <span>
            
                    
                    第一章 smart-http开发指南
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.2.1" data-path="../../smart-http/chapter-1/">
            
                <a href="../../smart-http/chapter-1/">
            
                    
                    1.1 快速上手
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2.2" data-path="../../smart-http/chapter-1/http_route.html">
            
                <a href="../../smart-http/chapter-1/http_route.html">
            
                    
                    1.2 请求路由
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2.3" data-path="../../smart-http/chapter-1/file_upload.html">
            
                <a href="../../smart-http/chapter-1/file_upload.html">
            
                    
                    1.3 文件上传/下载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2.4" data-path="../../smart-http/chapter-1/websocket.html">
            
                <a href="../../smart-http/chapter-1/websocket.html">
            
                    
                    1.4 WebSocket
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    技术分享
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../rpc/smart-socket-rpc.html">
            
                <a href="../rpc/smart-socket-rpc.html">
            
                    
                    smart-socket实现RPC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../firstfit/readme.html">
            
                <a href="../firstfit/readme.html">
            
                    
                    内存管理-首次适应算法
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4.3" data-path="readme.html">
            
                <a href="readme.html">
            
                    
                    Thread知多少
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../../donation.html">
            
                <a href="../../donation.html">
            
                    
                    关于捐赠
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >Thread知多少</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="thread&#x77E5;&#x591A;&#x5C11;">Thread&#x77E5;&#x591A;&#x5C11;</h1>
<p>&#x7EBF;&#x7A0B;&#x7C7B;Thread&#x662F;&#x4E00;&#x4E2A;&#x975E;&#x5E38;&#x57FA;&#x7840;&#x4E14;&#x975E;&#x5E38;&#x6838;&#x5FC3;&#x7684;&#x7C7B;&#xFF0C;&#x6240;&#x6709;&#x7684;&#x7684;Java&#x9879;&#x76EE;&#x4EE5;&#x53CA;&#x8FD0;&#x884C;&#x8FDB;&#x7A0B;&#x90FD;&#x8DDF;&#x5B83;&#x6709;&#x7740;&#x5FC5;&#x7136;&#x8054;&#x7CFB;&#x3002;
&#x4ECB;&#x7ECD;&#x5B83;&#x7684;&#x6587;&#x7AE0;&#x4E0D;&#x80DC;&#x679A;&#x4E3E;&#xFF0C;&#x672C;&#x6587;&#x5C06;&#x4ECE;&#x6E90;&#x7801;&#x89D2;&#x5EA6;&#x5BF9;&#x5176;&#x8FDB;&#x884C;&#x4E00;&#x6B21;&#x6DF1;&#x5EA6;&#x5256;&#x6790;&#xFF0C;&#x6216;&#x8BB8;&#x4F60;&#x4F1A;&#x4ECE;&#x4E2D;&#x4E86;&#x89E3;&#x5230;&#x81EA;&#x5DF1;&#x4E0D;&#x66FE;&#x7559;&#x610F;&#x7684;&#x77E5;&#x8BC6;&#x70B9;&#x3002;</p>
<p><img src="Thread.png" alt=""></p>
<p>&#x6211;&#x4EEC;&#x5C06;Thread&#x6E90;&#x7801;&#x4E2D;&#x7684;&#x5185;&#x5BB9;&#x8FDB;&#x884C;&#x4E86;&#x7B80;&#x5355;&#x89C4;&#x6574;&#xFF0C;&#x5927;&#x81F4;&#x53EF;&#x5206;&#x4E3A;&#x4E94;&#x5927;&#x5757;&#xFF1A;</p>
<ul>
<li>&#x7EBF;&#x7A0B;&#x72B6;&#x6001;</li>
<li>&#x8FC7;&#x65F6;&#x63A5;&#x53E3;</li>
<li>native&#x63A5;&#x53E3;</li>
<li>&#x9759;&#x6001;&#x65B9;&#x6CD5;</li>
<li>&#x666E;&#x901A;&#x65B9;&#x6CD5;</li>
</ul>
<h2 id="&#x7EBF;&#x7A0B;&#x72B6;&#x6001;">&#x7EBF;&#x7A0B;&#x72B6;&#x6001;</h2>
<p><img src="Thread_state.png" width="50%" height="50%"></p>
<h3 id="&#x65B0;&#x5EFA;&#x72B6;&#x6001;new">&#x65B0;&#x5EFA;&#x72B6;&#x6001;(NEW)</h3>
<p>&#x901A;&#x8FC7;<code>new</code>&#x64CD;&#x4F5C;&#x7B26;&#x521B;&#x5EFA;Thread&#x5BF9;&#x8C61;&#x540E;&#xFF0C;&#x5982;&#xFF1A;<code>new Thread()</code>&#xFF0C;&#x7EBF;&#x7A0B;&#x4FBF;&#x5904;&#x4E8E;&#x8BE5;&#x72B6;&#x6001;&#x3002;
&#x65B0;&#x5EFA;&#x72B6;&#x6001;&#x4E0B;&#x7684;&#x7EBF;&#x7A0B;&#x662F;&#x65E0;&#x6CD5;&#x4E3B;&#x52A8;&#x6267;&#x884C;&#x4EFB;&#x52A1;&#xFF1A;<code>run()</code>&#x65B9;&#x6CD5;&#x7684;&#x3002;
<img src="thread_init.jpeg" alt=""></p>
<ul>
<li>&#x6BCF;&#x4E2A;&#x7EBF;&#x7A0B;&#x5FC5;&#x7136;&#x5B58;&#x5728;&#x5173;&#x8054;&#x7684;&#x7236;&#x7EBF;&#x7A0B;&#x548C;&#x7EBF;&#x7A0B;&#x7EC4;</li>
<li>&#x7EBF;&#x7A0B;&#x4F18;&#x5148;&#x7EA7;&#x4E0D;&#x4F1A;&#x8D85;&#x8FC7;&#x5F52;&#x5C5E;&#x7EBF;&#x7A0B;&#x7EC4;&#x4F18;&#x5148;&#x7EA7;&#xFF08;&#x53C2;&#x8003;setPriority&#x7B97;&#x6CD5;&#xFF09;</li>
<li>&#x7EBF;&#x7A0B;&#x521D;&#x59CB;&#x5316;&#x9636;&#x6BB5;&#x5F88;&#x591A;&#x73AF;&#x8282;&#x5B58;&#x5728;&#x540C;&#x6B65;&#x9501;&#xFF08;addUnstarted&#x3001;nextThreadID&#x3001;nextThreadNum()&#xFF09;&#xFF0C;&#x56E0;&#x6B64;&#x5B9E;&#x9645;&#x4F7F;&#x7528;&#x4E2D;&#x63A8;&#x8350;&#x7EBF;&#x7A0B;&#x6C60;&#x3002;</li>
</ul>
<h3 id="&#x5C31;&#x7EEA;&#x72B6;&#x6001;runnable">&#x5C31;&#x7EEA;&#x72B6;&#x6001;(Runnable)</h3>
<p>&#x53EF;&#x8FD0;&#x884C;&#x7EBF;&#x7A0B;&#x7684;&#x7EBF;&#x7A0B;&#x72B6;&#x6001;&#x3002;&#x5904;&#x4E8E;&#x53EF;&#x8FD0;&#x884C;&#x72B6;&#x6001;&#x7684;&#x67D0;&#x4E00;&#x7EBF;&#x7A0B;&#x6B63;&#x5728; Java &#x865A;&#x62DF;&#x673A;&#x4E2D;&#x8FD0;&#x884C;&#xFF0C;&#x4F46;&#x5B83;&#x53EF;&#x80FD;&#x6B63;&#x5728;&#x7B49;&#x5F85;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x4E2D;&#x7684;&#x5176;&#x4ED6;&#x8D44;&#x6E90;&#xFF0C;&#x6BD4;&#x5982;&#x5904;&#x7406;&#x5668;&#x3002;
<img src="thread_start.jpeg" alt=""></p>
<ul>
<li>&#x591A;&#x6B21;&#x8C03;&#x7528;start&#x65B9;&#x6CD5;&#x4F1A;&#x89E6;&#x53D1;<code>IllegalThreadStateException</code>&#x5F02;&#x5E38;</li>
</ul>
<h3 id="&#x963B;&#x585E;&#x72B6;&#x6001;blocked">&#x963B;&#x585E;&#x72B6;&#x6001;(Blocked)</h3>
<p>&#x53D7;&#x963B;&#x585E;&#x5E76;&#x4E14;&#x6B63;&#x5728;&#x7B49;&#x5F85;&#x76D1;&#x89C6;&#x5668;&#x9501;&#x7684;&#x67D0;&#x4E00;&#x7EBF;&#x7A0B;&#x7684;&#x7EBF;&#x7A0B;&#x72B6;&#x6001;&#x3002;&#x5904;&#x4E8E;&#x53D7;&#x963B;&#x585E;&#x72B6;&#x6001;&#x7684;&#x67D0;&#x4E00;&#x7EBF;&#x7A0B;&#x6B63;&#x5728;&#x7B49;&#x5F85;&#x76D1;&#x89C6;&#x5668;&#x9501;&#xFF0C;&#x4EE5;&#x4FBF;&#x8FDB;&#x5165;&#x4E00;&#x4E2A;&#x540C;&#x6B65;&#x7684;&#x5757;/&#x65B9;&#x6CD5;&#xFF0C;&#x6216;&#x8005;&#x5728;&#x8C03;&#x7528; Object.wait &#x4E4B;&#x540E;&#x518D;&#x6B21;&#x8FDB;&#x5165;&#x540C;&#x6B65;&#x7684;&#x5757;/&#x65B9;&#x6CD5;&#x3002;</p>
<h3 id="&#x7B49;&#x5F85;&#x72B6;&#x6001;waiting">&#x7B49;&#x5F85;&#x72B6;&#x6001;(WAITING)</h3>
<p>&#x67D0;&#x4E00;&#x7B49;&#x5F85;&#x7EBF;&#x7A0B;&#x7684;&#x7EBF;&#x7A0B;&#x72B6;&#x6001;&#x3002;&#x67D0;&#x4E00;&#x7EBF;&#x7A0B;&#x56E0;&#x4E3A;&#x8C03;&#x7528;&#x4E0B;&#x5217;&#x65B9;&#x6CD5;&#x4E4B;&#x4E00;&#x800C;&#x5904;&#x4E8E;&#x7B49;&#x5F85;&#x72B6;&#x6001;&#xFF1A;</p>
<ul>
<li>&#x4E0D;&#x5E26;&#x8D85;&#x65F6;&#x503C;&#x7684; Object.wait</li>
<li>&#x4E0D;&#x5E26;&#x8D85;&#x65F6;&#x503C;&#x7684; Thread.join</li>
<li>LockSupport.park</li>
</ul>
<p>&#x5904;&#x4E8E;&#x7B49;&#x5F85;&#x72B6;&#x6001;&#x7684;&#x7EBF;&#x7A0B;&#x6B63;&#x7B49;&#x5F85;&#x53E6;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#xFF0C;&#x4EE5;&#x6267;&#x884C;&#x7279;&#x5B9A;&#x64CD;&#x4F5C;&#x3002; &#x4F8B;&#x5982;&#xFF0C;&#x5DF2;&#x7ECF;&#x5728;&#x67D0;&#x4E00;&#x5BF9;&#x8C61;&#x4E0A;&#x8C03;&#x7528;&#x4E86; Object.wait() &#x7684;&#x7EBF;&#x7A0B;&#x6B63;&#x7B49;&#x5F85;&#x53E6;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#xFF0C;&#x4EE5;&#x4FBF;&#x5728;&#x8BE5;&#x5BF9;&#x8C61;&#x4E0A;&#x8C03;&#x7528; Object.notify() &#x6216; Object.notifyAll()&#x3002;&#x5DF2;&#x7ECF;&#x8C03;&#x7528;&#x4E86; Thread.join() &#x7684;&#x7EBF;&#x7A0B;&#x6B63;&#x5728;&#x7B49;&#x5F85;&#x6307;&#x5B9A;&#x7EBF;&#x7A0B;&#x7EC8;&#x6B62;&#x3002;</p>
<h3 id="&#x9650;&#x65F6;&#x7B49;&#x5F85;&#x72B6;&#x6001;timedwaiting">&#x9650;&#x65F6;&#x7B49;&#x5F85;&#x72B6;&#x6001;(TIMED_WAITING)</h3>
<p>&#x5177;&#x6709;&#x6307;&#x5B9A;&#x7B49;&#x5F85;&#x65F6;&#x95F4;&#x7684;&#x67D0;&#x4E00;&#x7B49;&#x5F85;&#x7EBF;&#x7A0B;&#x7684;&#x7EBF;&#x7A0B;&#x72B6;&#x6001;&#x3002;&#x67D0;&#x4E00;&#x7EBF;&#x7A0B;&#x56E0;&#x4E3A;&#x8C03;&#x7528;&#x4EE5;&#x4E0B;&#x5E26;&#x6709;&#x6307;&#x5B9A;&#x6B63;&#x7B49;&#x5F85;&#x65F6;&#x95F4;&#x7684;&#x65B9;&#x6CD5;&#x4E4B;&#x4E00;&#x800C;&#x5904;&#x4E8E;&#x5B9A;&#x65F6;&#x7B49;&#x5F85;&#x72B6;&#x6001;&#xFF1A;</p>
<ul>
<li>Thread.sleep</li>
<li>&#x5E26;&#x6709;&#x8D85;&#x65F6;&#x503C;&#x7684; Object.wait</li>
<li>&#x5E26;&#x6709;&#x8D85;&#x65F6;&#x503C;&#x7684; Thread.join</li>
<li>LockSupport.parkNanos</li>
<li>LockSupport.parkUntil</li>
</ul>
<h3 id="&#x6B7B;&#x4EA1;&#x72B6;&#x6001;terminated">&#x6B7B;&#x4EA1;&#x72B6;&#x6001;(TERMINATED)</h3>
<p>&#x5DF2;&#x7EC8;&#x6B62;&#x7EBF;&#x7A0B;&#x7684;&#x7EBF;&#x7A0B;&#x72B6;&#x6001;&#x3002;&#x7EBF;&#x7A0B;&#x5DF2;&#x7ECF;&#x7ED3;&#x675F;&#x6267;&#x884C;&#x3002;&#x7EBF;&#x7A0B;&#x7ED3;&#x675F;&#x65F6;JVM&#x4F1A;&#x81EA;&#x52A8;&#x8C03;&#x7528;Thread&#x7684;&#x79C1;&#x6709;&#x65B9;&#x6CD5;exit&#x4EE5;&#x91CA;&#x653E;&#x8D44;&#x6E90;&#x3002;
<img src="Thread_exit.jpeg" alt=""></p>
<blockquote>
<p>&#x4F7F;&#x7528;ThreadLocal&#x82E5;&#x6CA1;&#x6709;&#x4E3B;&#x52A8;remove&#xFF0C;&#x5728;&#x7EBF;&#x7A0B;&#x4EFB;&#x52A1;&#x7ED3;&#x675F;&#x540E;&#x4E5F;&#x4F1A;&#x6267;&#x884C;&#x5185;&#x5B58;&#x56DE;&#x6536;&#x3002;&#x6240;&#x8C13;&#x7684;&#x5185;&#x5B58;&#x6CC4;&#x9732;&#x53EA;&#x5B58;&#x5728;&#x4E8E;&#x957F;&#x65F6;&#x95F4;&#x5904;&#x4E8E;Runnable&#x72B6;&#x6001;&#x7684;&#x7EBF;&#x7A0B;&#xFF0C;&#x4F8B;&#x5982;&#x7EBF;&#x7A0B;&#x6C60;&#x3002;</p>
</blockquote>
<h3 id="&#x7EBF;&#x7A0B;&#x72B6;&#x6001;&#x4EE3;&#x7801;&#x6F14;&#x793A;">&#x7EBF;&#x7A0B;&#x72B6;&#x6001;&#x4EE3;&#x7801;&#x6F14;&#x793A;</h3>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ThreadDemo</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> InterruptedException </span>{
        Thread t = <span class="hljs-keyword">new</span> Thread(<span class="hljs-keyword">new</span> Runnable() {
            <span class="hljs-meta">@Override</span>
            <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">run</span><span class="hljs-params">()</span> </span>{
                Thread currentThread = Thread.currentThread();
                <span class="hljs-keyword">try</span> {
                    System.out.println(<span class="hljs-string">&quot;sleep 150ms&quot;</span>);
                    Thread.sleep(<span class="hljs-number">150</span>);
                    System.out.println(<span class="hljs-string">&quot;sleep &#x7ED3;&#x675F;&quot;</span>);
                } <span class="hljs-keyword">catch</span> (InterruptedException e) {
                    e.printStackTrace();
                }

                <span class="hljs-keyword">synchronized</span> (currentThread) {
                    <span class="hljs-keyword">try</span> {
                        System.out.println(<span class="hljs-string">&quot;wait&#x7EBF;&#x7A0B;&quot;</span>);
                        currentThread.wait();
                        System.out.println(<span class="hljs-string">&quot;wait&#x7ED3;&#x675F;&quot;</span>);
                    } <span class="hljs-keyword">catch</span> (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println(currentThread.getState());
                System.out.println(<span class="hljs-string">&quot;&#x6267;&#x884C;&#x5B8C;&#x6210;&quot;</span>);
            }
        });
        <span class="hljs-comment">//NEW</span>
        System.out.println(<span class="hljs-string">&quot;&#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#x72B6;&#x6001;&quot;</span> + t.getState());

        t.start();

        <span class="hljs-comment">//TIMED_WAITING</span>
        Thread.sleep(<span class="hljs-number">100</span>);
        System.out.println(<span class="hljs-string">&quot;&#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#x72B6;&#x6001;&quot;</span> + t.getState());

        Thread.sleep(<span class="hljs-number">200</span>);
        System.out.println(<span class="hljs-string">&quot;&#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#x72B6;&#x6001;&quot;</span> + t.getState());
        <span class="hljs-keyword">synchronized</span> (t) {
            t.notify();
        }

        Thread.sleep(<span class="hljs-number">100</span>);
        System.out.println(<span class="hljs-string">&quot;&#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#x72B6;&#x6001;&quot;</span> + t.getState());
    }
}
</code></pre>
<h2 id="&#x8FC7;&#x65F6;&#x65B9;&#x6CD5;">&#x8FC7;&#x65F6;&#x65B9;&#x6CD5;</h2>
<ul>
<li><p>suspend&#x3001;resume<br>  suspend&#x65B9;&#x6CD5;&#x662F;&#x5C06;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#x6302;&#x8D77;&#xFF0C;&#x800C;resume&#x5219;&#x662F;&#x5C06;&#x4E00;&#x4E2A;&#x6302;&#x8D77;&#x7EBF;&#x7A0B;&#x590D;&#x6D3B;&#x7EE7;&#x7EED;&#x6267;&#x884C;&#xFF0C;&#x8FD9;&#x4E24;&#x4E2A;&#x662F;&#x76F8;&#x4E92;&#x914D;&#x5408;&#x7684;&#x65B9;&#x6CD5;&#x3002;&#x5982;&#x679C;&#x8FD9;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x5728;&#x67D0;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;&#x540C;&#x6B65;&#x5757;&#x4E2D;&#x6267;&#x884C;&#xFF0C;&#x4F1A;&#x51FA;&#x73B0;&#x6B7B;&#x9501;&#x3002;</p>
<pre><code class="lang-java">  <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ThreadDemo1</span> </span>{
  <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
      <span class="hljs-comment">//&#x6B63;&#x5E38;&#x60C5;&#x51B5;</span>
      Thread t1 = <span class="hljs-keyword">new</span> Thread(<span class="hljs-keyword">new</span> Runnable() {
          <span class="hljs-meta">@Override</span>
          <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">run</span><span class="hljs-params">()</span> </span>{
              System.out.println(<span class="hljs-string">&quot;&#x6302;&#x8D77;&quot;</span>);
              Thread.currentThread().suspend();
              System.out.println(<span class="hljs-string">&quot;&#x88AB;&#x5524;&#x9192;&#x4E86;&quot;</span>);
          }
      });
      t1.start();
      Thread t2 = <span class="hljs-keyword">new</span> Thread(<span class="hljs-keyword">new</span> Runnable() {
          <span class="hljs-meta">@Override</span>
          <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">run</span><span class="hljs-params">()</span> </span>{
              <span class="hljs-keyword">try</span> {
                  Thread.sleep(<span class="hljs-number">100</span>);
              } <span class="hljs-keyword">catch</span> (InterruptedException e) {
                  e.printStackTrace();
              }
              t1.resume();
          }
      });
      t2.start();

      <span class="hljs-comment">//&#x5F02;&#x5E38;&#x60C5;&#x51B5;</span>
      Object lock = <span class="hljs-keyword">new</span> Object();
      Thread t3 = <span class="hljs-keyword">new</span> Thread(<span class="hljs-keyword">new</span> Runnable() {
          <span class="hljs-meta">@Override</span>
          <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">run</span><span class="hljs-params">()</span> </span>{
              System.out.println(<span class="hljs-string">&quot;&#x6302;&#x8D77;&quot;</span>);
              <span class="hljs-keyword">synchronized</span> (lock) {
                  Thread.currentThread().suspend();
              }
              System.out.println(<span class="hljs-string">&quot;&#x88AB;&#x5524;&#x9192;&#x4E86;&quot;</span>);
          }
      });
      t3.start();
      Thread t4 = <span class="hljs-keyword">new</span> Thread(<span class="hljs-keyword">new</span> Runnable() {
          <span class="hljs-meta">@Override</span>
          <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">run</span><span class="hljs-params">()</span> </span>{
              <span class="hljs-keyword">try</span> {
                  Thread.sleep(<span class="hljs-number">100</span>);
              } <span class="hljs-keyword">catch</span> (InterruptedException e) {
                  e.printStackTrace();
              }
              System.out.println(<span class="hljs-string">&quot;&#x5C1D;&#x8BD5;&#x83B7;&#x53D6;&#x5BF9;&#x8C61;&#x9501;&quot;</span>);
              <span class="hljs-keyword">synchronized</span> (lock) {
                  System.out.println(<span class="hljs-string">&quot;&#x51C6;&#x5907;resume&quot;</span>);
                  t3.resume();
              }
          }
      });
      t4.start();
  }
}
</code></pre>
</li>
<li>stop<br>&#x975E;&#x5E38;&#x7C97;&#x66B4;&#x7684;&#x505C;&#x6B62;&#x7EBF;&#x7A0B;&#xFF0C;&#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#x53EF;&#x80FD;&#x6B63;&#x5728;&#x6267;&#x884C;&#x5173;&#x952E;&#x4E1A;&#x52A1;&#xFF0C;&#x5374;&#x88AB;&#x5F3A;&#x884C;&#x7EC8;&#x6B62;&#x3002;
<img src="Thread_stop.jpeg" alt=""></li>
<li>destory<br>  &#x8C03;&#x7528;&#x8BE5;&#x65B9;&#x6CD5;&#x4F1A;&#x76F4;&#x63A5;&#x5F02;&#x5E38;&#xFF0C;&#x60F3;&#x4E0D;&#x51FA;&#x8BBE;&#x8BA1;&#x5B83;&#x7684;&#x521D;&#x8877;&#x662F;&#x4EC0;&#x4E48;&#x3002;&#x53EF;&#x80FD;&#x9700;&#x8981;&#x770B;&#x6700;&#x65E9;&#x671F;&#x7684;Java&#x4EE3;&#x7801;&#x624D;&#x80FD;&#x77E5;&#x9053;&#x539F;&#x56E0;&#x3002;</li>
<li>countStackFrames<br>&#x8BA1;&#x7B97;&#x8BE5;&#x7EBF;&#x7A0B;&#x4E2D;&#x7684;&#x5806;&#x6808;&#x5E27;&#x6570;&#xFF0C;&#x9700;&#x8981;suspend&#x914D;&#x5408;&#x624D;&#x80FD;&#x4F7F;&#x7528;&#x3002;<h2 id="native&#x65B9;&#x6CD5;">native&#x65B9;&#x6CD5;</h2>
</li>
<li>currentThread&#xFF1A;&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x6B63;&#x5728;&#x6267;&#x884C;&#x7684;&#x7EBF;&#x7A0B;&#x5BF9;&#x8C61;</li>
<li><p>yield&#xFF1A;&#x6682;&#x505C;&#x5F53;&#x524D;&#x6B63;&#x5728;&#x6267;&#x884C;&#x7684;&#x7EBF;&#x7A0B;&#x5BF9;&#x8C61;&#xFF0C;&#x5E76;&#x6267;&#x884C;&#x5176;&#x4ED6;&#x7EBF;&#x7A0B;&#x3002;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">TreadDemo3</span> </span>{
  <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{

      <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">2</span>; i++) {
          <span class="hljs-keyword">new</span> Thread(<span class="hljs-keyword">new</span> Runnable() {
              <span class="hljs-meta">@Override</span>
              <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">run</span><span class="hljs-params">()</span> </span>{
                  <span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>;
                  <span class="hljs-keyword">while</span> (i++ &lt; <span class="hljs-number">100</span>) {
                      System.out.println(Thread.currentThread().getName() + <span class="hljs-string">&quot;:&quot;</span> + i);
                      Thread.yield();
                  }
              }
          }).start();
      }

  }
}
</code></pre>
</li>
<li>sleep&#xFF1A;&#x5728;&#x6307;&#x5B9A;&#x7684;&#x65F6;&#x957F;&#x5185;&#x8BA9;&#x5F53;&#x524D;&#x6B63;&#x5728;&#x6267;&#x884C;&#x7684;&#x7EBF;&#x7A0B;&#x4F11;&#x7720;&#xFF08;&#x6682;&#x505C;&#x6267;&#x884C;&#xFF09;&#xFF0C;&#x6B64;&#x64CD;&#x4F5C;&#x53D7;&#x5230;&#x7CFB;&#x7EDF;&#x8BA1;&#x65F6;&#x5668;&#x548C;&#x8C03;&#x5EA6;&#x7A0B;&#x5E8F;&#x7CBE;&#x5EA6;&#x548C;&#x51C6;&#x786E;&#x6027;&#x7684;&#x5F71;&#x54CD;&#x3002;&#x8BE5;&#x7EBF;&#x7A0B;&#x4E0D;&#x4E22;&#x5931;&#x4EFB;&#x4F55;&#x76D1;&#x89C6;&#x5668;&#x7684;&#x6240;&#x5C5E;&#x6743;&#xFF08;&#x6301;&#x6709;CPU&#x8D44;&#x6E90;&#xFF09;&#x3002;</li>
<li>isAlive&#xFF1A;so easy!</li>
<li><p>holdsLock&#xFF1A;&#x5982;&#x679C;&#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#x5728;&#x6307;&#x5B9A;&#x7684;&#x5BF9;&#x8C61;&#x4E0A;&#x4FDD;&#x6301;&#x76D1;&#x89C6;&#x5668;&#x9501;&#xFF0C;&#x5219;&#x8FD4;&#x56DE; true</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ThreadDemo4</span> </span>{
  <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
      Object object=<span class="hljs-keyword">new</span> Object();
      System.out.println(Thread.holdsLock(object));
      <span class="hljs-keyword">synchronized</span> (object){
          System.out.println(Thread.holdsLock(object));
      }
      System.out.println(Thread.holdsLock(object));
  }
}
</code></pre>
</li>
<li>isInterrupted</li>
<li>dumpThreads&#xFF1A;&#x5C06;&#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#x7684;&#x5806;&#x6808;&#x8DDF;&#x8E2A;&#x6253;&#x5370;&#x81F3;&#x6807;&#x51C6;&#x9519;&#x8BEF;&#x6D41;&#xFF0C;&#x5C31;&#x662F;new&#x4E86;&#x4E00;&#x4E2A;&#x5F02;&#x5E38;&#x5BF9;&#x8C61;&#x518D;&#x6267;&#x884C;<code>printStackTrace()</code>&#x3002;</li>
<li>getThreads&#xFF1A;&#x53CD;&#x9988;&#x5F53;&#x524D;&#x8FDB;&#x7A0B;&#x5185;&#x7684;&#x6240;&#x6709;&#x6D3B;&#x52A8;&#x7EBF;&#x7A0B;&#xFF0C;&#x88AB;<code>getAllStackTraces()</code>&#x8C03;&#x7528;&#x3002;</li>
<li>setPriority0&#xFF1A;&#x5C06;&#x7EBF;&#x7A0B;&#x4F18;&#x5148;&#x7EA7;&#x8BBE;&#x7F6E;&#x5230;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x5C42;&#x9762;&#x3002;</li>
<li>setNativeName&#xFF1A;&#x5C06;&#x7EBF;&#x7A0B;&#x540D;&#x79F0;&#x6CE8;&#x518C;&#x5230;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x5C42;&#x9762;&#x3002;</li>
</ul>
<h2 id="&#x9759;&#x6001;&#x65B9;&#x6CD5;">&#x9759;&#x6001;&#x65B9;&#x6CD5;</h2>
<p>&#x7565;&#xFF0C;&#x57FA;&#x672C;&#x6CA1;&#x5565;&#x597D;&#x8BB2;&#x7684;</p>
<h2 id="&#x666E;&#x901A;&#x65B9;&#x6CD5;">&#x666E;&#x901A;&#x65B9;&#x6CD5;</h2>
<ul>
<li><p>interrupt<br>  &#x4E2D;&#x65AD;&#x7EBF;&#x7A0B;&#x3002;&#x5982;&#x679C;&#x7EBF;&#x7A0B;&#x5728;&#x8C03;&#x7528; Object &#x7C7B;&#x7684; wait()&#x3001;wait(long) &#x6216; wait(long, int) &#x65B9;&#x6CD5;&#xFF0C;&#x6216;&#x8005;&#x8BE5;&#x7C7B;&#x7684; join()&#x3001;join(long)&#x3001;join(long, int)&#x3001;sleep(long) &#x6216; sleep(long, int) &#x65B9;&#x6CD5;&#x8FC7;&#x7A0B;&#x4E2D;&#x53D7;&#x963B;&#xFF0C;&#x5219;&#x5176;&#x4E2D;&#x65AD;&#x72B6;&#x6001;&#x5C06;&#x88AB;&#x6E05;&#x9664;&#xFF0C;&#x5B83;&#x8FD8;&#x5C06;&#x6536;&#x5230;&#x4E00;&#x4E2A; InterruptedException&#x3002;</p>
<pre><code class="lang-java">  <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ThreadDemo5</span> </span>{
  <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> InterruptedException </span>{
      Object lock = <span class="hljs-keyword">new</span> Object();
      Thread t = <span class="hljs-keyword">new</span> Thread(<span class="hljs-keyword">new</span> Runnable() {
          <span class="hljs-meta">@Override</span>
          <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">run</span><span class="hljs-params">()</span> </span>{
              <span class="hljs-keyword">try</span> {
                  Thread.sleep(<span class="hljs-number">1000</span>);
              } <span class="hljs-keyword">catch</span> (InterruptedException e) {
                  e.printStackTrace();
              }
              <span class="hljs-keyword">synchronized</span> (lock) {
                  <span class="hljs-keyword">try</span> {
                      lock.wait();
                  } <span class="hljs-keyword">catch</span> (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
          }
      });
      t.start();

      Thread.sleep(<span class="hljs-number">100</span>);
      t.interrupt();
      System.out.println(<span class="hljs-string">&quot;&#x4E2D;&#x65AD;t&#x7684;sleep&quot;</span>);
      Thread.sleep(<span class="hljs-number">100</span>);
      t.interrupt();
      System.out.println(<span class="hljs-string">&quot;&#x4E2D;&#x65AD;t&#x7684;wait&quot;</span>);
  }
}
</code></pre>
</li>
<li><p>join&#xFF1A;&#x7B49;&#x5F85;&#x8BE5;&#x7EBF;&#x7A0B;&#x7EC8;&#x6B62;&#x3002;
<img src="thread_join.jpeg" alt="">
&#x901A;&#x8FC7;wait&#x63A5;&#x53E3;&#x6765;&#x5B9E;&#x73B0;join&#x529F;&#x80FD;&#x3002;&#x5982;&#x4E0B;&#x4EE3;&#x7801;&#x6240;&#x793A;&#x5F53;&#x7EBF;&#x7A0B;t2&#x6267;&#x884C;<code>t1.join()</code>&#x540E;&#xFF0C;t2&#x7EBF;&#x7A0B;&#x963B;&#x585E;&#xFF0C;&#x5F85;t1&#x7EBF;&#x7A0B;&#x6267;&#x884C;&#x5B8C;&#x6BD5;&#x540E;JVM&#x4F1A;&#x901A;&#x8FC7;notifyAll&#x6765;&#x5524;&#x9192;t2&#x7EBF;&#x7A0B;&#x3002;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ThreadDemo6</span> </span>{
  <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
      Thread t1 = <span class="hljs-keyword">new</span> Thread(<span class="hljs-keyword">new</span> Runnable() {
          <span class="hljs-meta">@Override</span>
          <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">run</span><span class="hljs-params">()</span> </span>{
              <span class="hljs-keyword">try</span> {
                  Thread.sleep(<span class="hljs-number">100</span>);
              } <span class="hljs-keyword">catch</span> (InterruptedException e) {
                  e.printStackTrace();
              }
              System.out.println(<span class="hljs-string">&quot;thread 1&quot;</span>);
          }
      });

      Thread t2 = <span class="hljs-keyword">new</span> Thread(<span class="hljs-keyword">new</span> Runnable() {
          <span class="hljs-meta">@Override</span>
          <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">run</span><span class="hljs-params">()</span> </span>{
              <span class="hljs-keyword">try</span> {
                  t1.join();
              } <span class="hljs-keyword">catch</span> (InterruptedException e) {
                  e.printStackTrace();
              }
              System.out.println(<span class="hljs-string">&quot;thread 2&quot;</span>);
          }
      });
      t1.start();
      t2.start();
  }
}
</code></pre>
</li>
<li>setDaemon<br>  &#x5C06;&#x8BE5;&#x7EBF;&#x7A0B;&#x6807;&#x8BB0;&#x4E3A;&#x5B88;&#x62A4;&#x7EBF;&#x7A0B;&#x6216;&#x7528;&#x6237;&#x7EBF;&#x7A0B;&#x3002;&#x5F53;&#x6B63;&#x5728;&#x8FD0;&#x884C;&#x7684;&#x7EBF;&#x7A0B;&#x90FD;&#x662F;&#x5B88;&#x62A4;&#x7EBF;&#x7A0B;&#x65F6;&#xFF0C;Java &#x865A;&#x62DF;&#x673A;&#x9000;&#x51FA;&#x3002;&#x8BE5;&#x65B9;&#x6CD5;&#x5FC5;&#x987B;&#x5728;&#x542F;&#x52A8;&#x7EBF;&#x7A0B;&#x524D;&#x8C03;&#x7528;&#x3002;</li>
<li><p>setContextClassLoader<br>  &#x8FD4;&#x56DE;&#x8BE5;&#x7EBF;&#x7A0B;&#x7684;&#x4E0A;&#x4E0B;&#x6587; ClassLoader&#x3002;&#x4E0A;&#x4E0B;&#x6587; ClassLoader &#x7531;&#x7EBF;&#x7A0B;&#x521B;&#x5EFA;&#x8005;&#x63D0;&#x4F9B;&#xFF0C;&#x4F9B;&#x8FD0;&#x884C;&#x4E8E;&#x8BE5;&#x7EBF;&#x7A0B;&#x4E2D;&#x7684;&#x4EE3;&#x7801;&#x5728;&#x52A0;&#x8F7D;&#x7C7B;&#x548C;&#x8D44;&#x6E90;&#x65F6;&#x4F7F;&#x7528;&#x3002;&#x5982;&#x679C;&#x672A;&#x8BBE;&#x5B9A;&#xFF0C;&#x5219;&#x9ED8;&#x8BA4;&#x4E3A;&#x7236;&#x7EBF;&#x7A0B;&#x7684; ClassLoader &#x4E0A;&#x4E0B;&#x6587;&#x3002;&#x539F;&#x59CB;&#x7EBF;&#x7A0B;&#x7684;&#x4E0A;&#x4E0B;&#x6587; ClassLoader &#x901A;&#x5E38;&#x8BBE;&#x5B9A;&#x4E3A;&#x7528;&#x4E8E;&#x52A0;&#x8F7D;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7684;&#x7C7B;&#x52A0;&#x8F7D;&#x5668;</p>
</li>
<li><p>getContextClassLoader<br>&#x8BBE;&#x7F6E;&#x8BE5;&#x7EBF;&#x7A0B;&#x7684;&#x4E0A;&#x4E0B;&#x6587; ClassLoader&#x3002;&#x4E0A;&#x4E0B;&#x6587; ClassLoader &#x53EF;&#x4EE5;&#x5728;&#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x8BBE;&#x7F6E;&#xFF0C;&#x5E76;&#x5141;&#x8BB8;&#x521B;&#x5EFA;&#x8005;&#x5728;&#x52A0;&#x8F7D;&#x7C7B;&#x548C;&#x8D44;&#x6E90;&#x65F6;&#x5411;&#x8BE5;&#x7EBF;&#x7A0B;&#x4E2D;&#x8FD0;&#x884C;&#x7684;&#x4EE3;&#x7801;&#x63D0;&#x4F9B;&#x9002;&#x5F53;&#x7684;&#x7C7B;&#x52A0;&#x8F7D;&#x5668;&#x3002;</p>
</li>
</ul>
<blockquote>
<p>&#x6D89;&#x53CA;&#x5230;&#x7C7B;&#x52A0;&#x8F7D;&#x6216;&#x9694;&#x79BB;&#x7684;&#x9879;&#x76EE;&#x901A;&#x5E38;&#x4F1A;&#x91CD;&#x7F6E;&#x7EBF;&#x7A0B;&#x4E2D;&#x7684;classLoader.</p>
</blockquote>
<p><strong>&#x8FD8;&#x6709;&#x4E00;&#x4E9B;&#x8FB9;&#x8FB9;&#x89D2;&#x89D2;&#x7684;&#x65B9;&#x6CD5;&#x81EA;&#x5DF1;&#x53BB;&#x770B;&#x6E90;&#x7801;&#x3002;</strong> </p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; smartboot.org 2018 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2019-07-12 17:20:11
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../firstfit/readme.html" class="navigation navigation-prev " aria-label="Previous page: 内存管理-首次适应算法">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../../donation.html" class="navigation navigation-next " aria-label="Next page: 关于捐赠">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Thread知多少","level":"1.4.3","depth":2,"next":{"title":"关于捐赠","level":"1.5","depth":1,"path":"donation.md","ref":"donation.md","articles":[]},"previous":{"title":"内存管理-首次适应算法","level":"1.4.2","depth":2,"path":"share/firstfit/readme.md","ref":"share/firstfit/readme.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","-sharing","search-plus","expandable-chapters-interactive","tbfed-pagefooter","github","github-buttons","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy smartboot.org 2018","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"github":{"url":"https://github.com/smartboot/smart-socket"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"expandable-chapters-interactive":{},"github-buttons":{"buttons":[{"user":"smartboot","repo":"smart-socket","type":"star","size":"small","count":true}]},"edit-link":{"label":"Edit This Page","base":"https://gitee.com/smartboot/book/edit/master"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"search-plus":{}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"smartboot 中文指南","language":"en","gitbook":"*","description":"本文涵盖了smartboot下所有项目的技术手册"},"file":{"path":"share/thread/readme.md","mtime":"2019-07-12T09:20:11.390Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2020-04-02T05:22:17.739Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters-interactive/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

